<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号" class="form-item">
              <a-input placeholder="请输入单据编号" v-model="queryParam.documentNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="车牌号" class="form-item">
              <a-input placeholder="请输入车牌" v-model="queryParam.carNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属单位">
              <select-Company-input :disabled="formDisabled" v-model="queryParam.affiliatedUnit"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="车辆类型">
              <j-dict-select-tag  type="list" dictCode="car_type_oa" v-model="queryParam.carType" placeholder="请选择车辆类型" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="购置日期">
              <j-date  placeholder="请选择购置日期" v-model="queryParam.purchaseTimeCheck"  style="width: 100%" />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpCarInfo:add')">新增</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('车辆信息')" :disabled="isDisabledAuth('erpCarInfo:export')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpCarInfo:import')">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpCarInfo:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        :components="draggableComponent"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="detail" :title="text" slot-scope="text, record" @click="getDetail(record)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="edit"
            @click="handleEdit(record)"
            :disabled="isDisabledAuth('erpCarInfo:edit')"
        />
        <a-divider type="vertical"/>
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="delete"
            :disabled="isDisabledAuth('erpCarInfo:delete')"/>
        </a-popconfirm>
        <template v-if="record.carState==3">
          <a-divider type="vertical"/>
          <a-popconfirm title="确定取车吗?" @confirm="() => backRequest(record)">
            <a href="javascript:;" :disabled="isDisabledAuth('erpCarInfo:backCar')">取车</a>
          </a-popconfirm>
        </template>
        <a-divider type="vertical"/>
          <a href="javascript:;" @click="JumpRequest(record)">维保</a>
        </span>
      </a-table>
    </div>
    <erp-car-info-modal ref="modalForm" @ok="modalFormOk"></erp-car-info-modal>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpCarInfoModal from './modules/ErpCarInfoModal'
import { getAction, httpAction } from '@/api/manage'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput';
export default {
    name: 'ErpCarInfoList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpCarInfoModal,
      SelectCompanyInput
    },
    data () {
      return {
        description: '车辆信息管理页面',
        formDisabled: false,
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'documentNo',
            width:200,
            scopedSlots: { customRender: 'detail' },
          },
          {
            title:'所属单位',
            align:"center",
            width:360,
            dataIndex: 'affiliatedUnit_dictText',
          },
          // {
          //   title:'车辆名称',
          //   align:"center",
          //   dataIndex: 'carName',
          // },
          {
            title:'车牌',
            align:"center",
            width:120,
            dataIndex: 'carNum',
          },
          {
            title:'车辆类型',
            align:"center",
            width:120,
            dataIndex: 'carType_dictText',
          },
          // {
          //   title:'座位数',
          //   align:"center",
          //   dataIndex: 'carSeatNum_dictText',
          // },
          {
            title:'购置日期',
            align:"center",
            width:120,
            dataIndex: 'purchaseTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          // {
          //   title:'车辆状态',
          //   align:"center",
          //   dataIndex: 'carState_dictText',
          // },
          // {
          //   title:'初次购买保险时间',
          //   align:"center",
          //   dataIndex: 'firstBuyInsuranceTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'保险到期时间',
          //   align:"center",
          //   dataIndex: 'insuranceEndTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          {
            title:'管理员',
            align:"center",
            // width:80,
            dataIndex: 'carAdmin_dictText',
          },
          // {
          //   title:'租赁方式',
          //   align:"center",
          //   dataIndex: 'leaseType_dictText',
          // },
          // {
          //   title:'租金',
          //   align:"center",
          //   dataIndex: 'rent',
          // },
          // {
          //   title:'备注',
          //   align:"center",
          //   dataIndex: 'remark',
          // },
          // {
          //   title:'附件信息',
          //   align:"center",
          //   dataIndex: 'fileInfo',
          //   scopedSlots: {customRender: 'fileSlot'}
          // },
          // {
          //   title:'创建人',
          //   align:"center",
          //   dataIndex: 'createBy',
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:200,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/oa/car/erpCarInfo/list",
          delete: "/api/erp/oa/car/erpCarInfo/delete",
          deleteBatch: "/api/erp/oa/car/erpCarInfo/deleteBatch",
          exportXlsUrl: "/api/erp/oa/car/erpCarInfo/exportXls",
          importExcelUrl: "/api/erpoa/car/erpCarInfo/importExcel",
          backCar:"/api/erp/oa/car/erpCarInfo/getCar",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'documentNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'affiliatedUnit',text:'所属单位',dictCode:''})
        fieldList.push({type:'string',value:'carName',text:'车辆名称',dictCode:''})
        fieldList.push({type:'string',value:'carNum',text:'车牌',dictCode:''})
        fieldList.push({type:'string',value:'carType',text:'车辆类型',dictCode:''})
        fieldList.push({type:'string',value:'carSeatNum',text:'座位数',dictCode:''})
        fieldList.push({type:'date',value:'purchaseTime',text:'购置日期'})
        fieldList.push({type:'string',value:'carState',text:'车辆状态',dictCode:''})
        fieldList.push({type:'date',value:'firstBuyInsuranceTime',text:'初次购买保险时间'})
        fieldList.push({type:'date',value:'insuranceEndTime',text:'保险到期时间'})
        fieldList.push({type:'string',value:'carAdmin',text:'车辆管理员',dictCode:''})
        fieldList.push({type:'string',value:'leaseType',text:'租赁方式',dictCode:''})
        fieldList.push({type:'string',value:'rent',text:'租金（元）',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'fileInfo',text:'附件信息',dictCode:''})
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        this.superFieldList = fieldList
      },
      backRequest(record){
        getAction(this.url.backCar, { id:record.id}).then(res => {
          if (res.success) {
            this.$message.success(res.message);
            this.loadData();
          }
        })
      },
      JumpRequest(record){
        console.log(record);
        this.$router.push({
          path: '/oa/carmaintenance/ErpCarMaintenanceList',
          query: {
            id: record.id
          }
        })
      },
      //查看详情
      getDetail(record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
